Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve diagnostics for StructExpression #4357

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

kfcripps
Copy link
Contributor

No description provided.

@kfcripps kfcripps force-pushed the improve-diagnostics-structexpr branch from a67d4a8 to bcde4cd Compare January 24, 2024 15:35
Copy link
Contributor

@jafingerhut jafingerhut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not reviewed the C++ changes in any detail, but I have looked at the changes in the error messages, and they look reasonable to me.

@fruffy
Copy link
Collaborator

fruffy commented Jan 24, 2024

I am not sure why a cstring could be null here. Let me debug this.

@kfcripps
Copy link
Contributor Author

I am not sure why a cstring could be null here. Let me debug this.

Thanks!

Copy link
Collaborator

@fruffy fruffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the reason for the crash. No problem with your code but there is a problem with the way cstrings are initialized.

If you just declare them cstring var; the internal character will be a nullptr and the cstring will be invalid. I think this is something that should be fix, not sure why the class is written this way.

Either way, applying this patch should fix the problem:

diff --git a/backends/p4tools/p4tools.def b/backends/p4tools/p4tools.def
index ee2066443..aec5bb13d 100644
--- a/backends/p4tools/p4tools.def
+++ b/backends/p4tools/p4tools.def
@@ -211,7 +211,7 @@ public:
     inline cstring concolicMethodName = "";
 
     toString {
-        cstring argumentStr;
+        cstring argumentStr = "";
         cstring sep = "";
         for (const auto *arg : *arguments) {
             argumentStr += sep + arg->toString();

@@ -482,6 +482,7 @@ class StructExpression : Expression {
size_t size = components.size();
return components.at(size - 1)->is<IR::NamedDots>();
}
cstring toString() const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either be marked override or implemented in the form of

toString {
    cstring str = "{";
    if (!components.empty()) {
        cstring exprStr = components.at(0)->expression->toString();
        str += " " + components.at(0)->toString() + " = " + exprStr;
    }
    for (unsigned i = 1; i < size(); i++) {
        cstring exprStr = components.at(i)->expression->toString();
        str += ", " + components.at(i)->toString() + " = " + exprStr;
    }
    return str + " }";
}

like with other nodes.

Copy link
Contributor

@jafingerhut jafingerhut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not reviewed the C++ changes in any detail, but I have looked at the changes in the error messages, and they look reasonable to me.

@fruffy
Copy link
Collaborator

fruffy commented Jan 25, 2024

@kfcripps Are you able to enable automerge for these PRs? If not, I can toggle it.

@kfcripps
Copy link
Contributor Author

@fruffy How do I do that?

@fruffy
Copy link
Collaborator

fruffy commented Jan 25, 2024

image

The CI has this option, but I believe you need merge rights for this.

@kfcripps
Copy link
Contributor Author

Yeah, I've never contributed here before, so I don't have any rights in this repo.

@fruffy
Copy link
Collaborator

fruffy commented Jan 25, 2024

I can enable it for the PRs, if you want me to.

@kfcripps
Copy link
Contributor Author

Would that enable auto-merging for all future PRs, or do you have to enable it individually for each?

@vlstill
Copy link
Contributor

vlstill commented Jan 25, 2024

It is for each PR separately. In general when you have no write access, you can ask someone to merge the PR for you once you are happy with it and it is approved. In its current state it will probably have to be updated/rebased before that can be done (you will probably see a button for that).
image

@kfcripps
Copy link
Contributor Author

Ok, I don't see why not - please enable it for my PRs. Thanks

@kfcripps kfcripps force-pushed the improve-diagnostics-structexpr branch from a97cbd3 to 145229d Compare January 25, 2024 15:32
@kfcripps
Copy link
Contributor Author

Rebased

@vlstill vlstill enabled auto-merge (squash) January 25, 2024 15:37
@kfcripps
Copy link
Contributor Author

Looks like the build_indirect job is stuck?

@vlstill vlstill merged commit affc088 into p4lang:main Jan 25, 2024
16 checks passed
@kfcripps kfcripps deleted the improve-diagnostics-structexpr branch July 1, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants